package com.education.platform.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 会话表
 *
 * @author education-platform
 * @since 2024-10-07
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("conversation")
@JsonIgnoreProperties(value = {"handler"})
public class Conversation {

    /**
     * 会话ID
     */
    @TableId(value = "id", type = IdType.INPUT)
    private String id;

    /**
     * 会话类型
     */
    @TableField("type")
    private String type;

    /**
     * 会话名称
     */
    @TableField("name")
    private String name;

    /**
     * 会话头像
     */
    @TableField("avatar")
    private String avatar;

    /**
     * 参与者列表
     */
    @TableField("participants")
    private String participants;

    /**
     * 最后一条消息ID
     */
    @TableField("last_message_id")
    private Long lastMessageId;

    /**
     * 最后消息时间
     */
    @TableField("last_message_time")
    private LocalDateTime lastMessageTime;

    /**
     * 最后消息内容
     */
    @TableField("last_message_content")
    private String lastMessageContent;

    /**
     * 创建时间
     */
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    /**
     * 更新时间
     */
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;

    // 关联对象（用于XML映射）
    @TableField(exist = false)
    private List<User> participantUsers;

    @TableField(exist = false)
    private Message lastMessage;

    @TableField(exist = false)
    private Integer unreadCount;
    
    // 对方用户信息（私聊时使用）
    @TableField(exist = false)
    private Long otherUserId;
    
    @TableField(exist = false)
    private String otherUserName;
    
    @TableField(exist = false)
    private String otherUserAvatar;

    // 枚举定义
    public enum Type {
        PRIVATE("私聊"),
        GROUP("群聊");

        private final String description;

        Type(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }
}
